import dayjs from "dayjs";

export function dateFormat(time: string, type: 'date' | 'datetime' | 'time' = 'date'){
  const dayTime = dayjs(time)
  if(dayTime.isValid()){
    let formatStr
    switch (type){
      case "date":
        formatStr = "YYYY-MM-DD"
        break;
      case "datetime":
        formatStr = "YYYY-MM-DD HH:mm:ss"
        break;
      case "time":
        formatStr = "HH:mm:ss"
        break;
      default:
        formatStr = "YYYY-MM-DD"
        break;
    }
    return dayTime.format(formatStr)
  }
  return ""
}